package com.example.anday3;

import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.anday3.adapter.StrListAdapter;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    ListView listView;
    Button button;
    TextView txtView;
    List<String>  list;
//    ArrayAdapter arrayAdapter;
StrListAdapter strListAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        listView=findViewById(R.id.mylist);
        txtView=findViewById(R.id.txt);
        button=findViewById(R.id.btn);
        list=new ArrayList<>();
        list.add("aaaa");
        list.add("bbbbbb");
        list.add("ccc");
        list.add("ddd");
        list.add("eee");
//         arrayAdapter=new ArrayAdapter(this,
//                android.R.layout.simple_list_item_1,list);
//        listView.setAdapter(arrayAdapter);

        button.setOnClickListener(this);
        strListAdapter=new StrListAdapter(this,list);
        listView.setAdapter(strListAdapter);

    }

    @Override
    public void onClick(View v) {
        if(txtView.getText().toString().length()>0){
            list.add(txtView.getText().toString());

           strListAdapter.notifyDataSetChanged();
            txtView.setText("");
        }
    }
}